/****************************************************************************
**  气泡
****************************************************************************/
.import QtQuick 2.0 as QQ


var BubbleTailWitdh = 10        // 气泡尾巴
var BubbleMargin = 10           // 文本外边框
var BubbleRadius = 6
var BubbleTailHeight = 3

function drawBubble(context) {

    var bubbleTailY = container.iconHeight/2 + BubbleTailWitdh * 0.7     // 尾巴高度
    // Context2D
    context.beginPath()
    context.clearRect(0,0,container.width, container.height)
    context.roundedRect(isSend ? 0 : BubbleTailWitdh, 0,
                        container.width - BubbleTailWitdh, container.height,
                        BubbleRadius, BubbleRadius);
    // 最上 中间 最下
    context.moveTo(isSend ? container.width - BubbleTailWitdh : BubbleTailWitdh, bubbleTailY - BubbleTailHeight*0.5);
    context.quadraticCurveTo(isSend ? container.width - BubbleTailWitdh / 4 : BubbleTailWitdh / 2, bubbleTailY ,
                             isSend ? container.width : 0, container.iconHeight/2 );
    context.quadraticCurveTo(isSend ? container.width - BubbleTailWitdh / 4 : BubbleTailWitdh / 2, bubbleTailY + BubbleTailHeight ,
                             isSend ? container.width - BubbleTailWitdh : BubbleTailWitdh, bubbleTailY + BubbleTailHeight *2 );
    context.closePath()
    context.fillStyle = isSend ?  "#12B7F5" : "#FFFFFF"

    context.fill()
}

function initText() {
    text.font.pixelSize = 14
    text.font.family = "Microsoft Yahei"
    text.anchors.margins = BubbleMargin
    if (isSend) {
        text.color = "#FFFFFF"
        text.anchors.rightMargin = BubbleMargin + BubbleTailWitdh
    } else {
        text.color = "#0E0E0E"
        text.anchors.leftMargin = BubbleMargin + BubbleTailWitdh
    }
    var textheight =  iconHeight * 1.1
    container.width = (text.contentWidth + BubbleMargin*2 + BubbleTailWitdh) > maxWidth ? maxWidth : text.contentWidth + BubbleMargin*2 + BubbleTailWitdh
    container.height = text.contentHeight + BubbleMargin*2 < textheight ? textheight : text.contentHeight + BubbleMargin*2


}

function reUpdateSize() {
    var textheight =  iconHeight * 1.1
    container.width = (text.contentWidth + BubbleMargin*2 + BubbleTailWitdh) > maxWidth ? maxWidth : (text.contentWidth + BubbleMargin*2 + BubbleTailWitdh)
    container.height = text.contentHeight + BubbleMargin*2  < textheight ? textheight : text.contentHeight + BubbleMargin*2
}
